<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.12"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>emp-toolkit: /Users/wangxiao/git/emp-toolkit/emp-tool/utils/prg.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="logo-full-doxygen.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">emp-toolkit
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.12 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('prg_8h_source.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">prg.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="prg_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#ifndef PRG_H__</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor">#define PRG_H__</span></div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="utils_2block_8h.html">block.h</a>&quot;</span></div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="aes_8h.html">garble/aes.h</a>&quot;</span></div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="config_8h.html">config.h</a>&quot;</span></div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="utils__ec_8h.html">utils_ec.h</a>&quot;</span></div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="preprocessor">#include &lt;stdio.h&gt;</span></div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="preprocessor">#include &lt;stdarg.h&gt;</span></div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#include &lt;gmp.h&gt;</span></div><div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="keyword">class </span><a class="code" href="class_p_r_g.html">PRG</a>;</div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="keyword">static</span> <a class="code" href="class_p_r_g.html">PRG</a> * rnd = <span class="keyword">nullptr</span>;</div><div class="line"><a name="l00016"></a><span class="lineno"><a class="line" href="class_p_r_g.html">   16</a></span>&#160;<span class="keyword">class </span><a class="code" href="class_p_r_g.html">PRG</a> { <span class="keyword">public</span>:</div><div class="line"><a name="l00017"></a><span class="lineno"><a class="line" href="class_p_r_g.html#abbf584745c33fc90ba28cc4af194ce1a">   17</a></span>&#160;    uint64_t <a class="code" href="class_p_r_g.html#abbf584745c33fc90ba28cc4af194ce1a">counter</a> = 0;</div><div class="line"><a name="l00018"></a><span class="lineno"><a class="line" href="class_p_r_g.html#a567930c31c3371f18099e5c8302aff71">   18</a></span>&#160;    <a class="code" href="struct_a_e_s___k_e_y.html">AES_KEY</a> <a class="code" href="class_p_r_g.html#a567930c31c3371f18099e5c8302aff71">aes</a>;</div><div class="line"><a name="l00019"></a><span class="lineno"><a class="line" href="class_p_r_g.html#a6581a2e36b6441e589e19e1af0ecba79">   19</a></span>&#160;    <a class="code" href="class_p_r_g.html#a6581a2e36b6441e589e19e1af0ecba79">PRG</a>(<span class="keyword">const</span> <span class="keywordtype">void</span> * seed = <span class="keyword">nullptr</span>, <span class="keywordtype">int</span> <span class="keywordtype">id</span> = 0) {</div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;        <span class="keywordflow">if</span>(rnd == <span class="keyword">nullptr</span>) {</div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;            <span class="keywordtype">char</span> data[16];</div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;            FILE *fp;</div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;            fp = fopen(<span class="stringliteral">&quot;/dev/urandom&quot;</span>, <span class="stringliteral">&quot;r&quot;</span>);</div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;            <span class="keywordtype">int</span> r_bytes = 0;</div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;            <span class="keywordflow">while</span> (r_bytes &lt; 16) {</div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;                <span class="keywordtype">int</span> r = fread(&amp;data, 1, 16, fp);</div><div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;                <span class="keywordflow">if</span> (r &lt; 0) exit(1);</div><div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;                r_bytes+=r;</div><div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;            }</div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;            fclose(fp);</div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;            rnd = <span class="keyword">this</span>;<span class="comment">//make rnd not nullptr, to avoiding infinite recursion.</span></div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;            rnd = <span class="keyword">new</span> <a class="code" href="class_p_r_g.html#a6581a2e36b6441e589e19e1af0ecba79">PRG</a>(data);</div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;        }</div><div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;        <span class="keywordflow">if</span> (seed == <span class="keyword">nullptr</span>) {</div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;            <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> data;</div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;            rnd-&gt;<a class="code" href="class_p_r_g.html#a822a2e39f1d2629b881ce9b3b8d66bf9">random_block</a>(&amp;data, 1);</div><div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;            <a class="code" href="class_p_r_g.html#a71e9b3256b36b72e1198064469381b2c">reseed</a>(&amp;data, <span class="keywordtype">id</span>);</div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;        } <span class="keywordflow">else</span></div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;            <a class="code" href="class_p_r_g.html#a71e9b3256b36b72e1198064469381b2c">reseed</a>(seed, <span class="keywordtype">id</span>);</div><div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;    }</div><div class="line"><a name="l00041"></a><span class="lineno"><a class="line" href="class_p_r_g.html#a71e9b3256b36b72e1198064469381b2c">   41</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_p_r_g.html#a71e9b3256b36b72e1198064469381b2c">reseed</a>(<span class="keyword">const</span> <span class="keywordtype">void</span> * key, uint64_t <span class="keywordtype">id</span> = 0) {</div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;        <span class="keyword">const</span> <span class="keywordtype">char</span> * k = (<span class="keyword">const</span> <span class="keywordtype">char</span> *)key;</div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;        __m128i v = _mm_load_si128((__m128i*)&amp;k[0]);</div><div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;        v = <a class="code" href="utils_2block_8h.html#a939b7dd0e7479964d6fe6984b90dd5ce">xorBlocks</a>(v, <a class="code" href="utils_2block_8h.html#a371865208357f993ac4e691d54bd806d">makeBlock</a>(0LL, <span class="keywordtype">id</span>));</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;        AES_set_encrypt_key(v, &amp;aes);</div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;        counter = 0;</div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    }</div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;</div><div class="line"><a name="l00049"></a><span class="lineno"><a class="line" href="class_p_r_g.html#a3b64a0c91c31cec853c1829953409520">   49</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_p_r_g.html#a3b64a0c91c31cec853c1829953409520">random_data</a>(<span class="keywordtype">void</span> *data, <span class="keywordtype">int</span> nbytes) {</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;        <a class="code" href="class_p_r_g.html#a822a2e39f1d2629b881ce9b3b8d66bf9">random_block</a>((<a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> *)data, nbytes/16);</div><div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;        <span class="keywordflow">if</span> (nbytes % 16 != 0) {</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;            <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> extra;</div><div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;            <a class="code" href="class_p_r_g.html#a822a2e39f1d2629b881ce9b3b8d66bf9">random_block</a>(&amp;extra, 1);</div><div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;            memcpy((nbytes/16*16)+(<span class="keywordtype">char</span> *) data, &amp;extra, nbytes%16);</div><div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;        }</div><div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;    }</div><div class="line"><a name="l00057"></a><span class="lineno"><a class="line" href="class_p_r_g.html#a364a86de7a055f92198d2d8762f0288c">   57</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_p_r_g.html#a364a86de7a055f92198d2d8762f0288c">random_bool</a>(<span class="keywordtype">bool</span> * data, <span class="keywordtype">int</span> length) {</div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;        uint8_t * uint_data = (uint8_t*)data;</div><div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;        <a class="code" href="class_p_r_g.html#a3b64a0c91c31cec853c1829953409520">random_data</a>(uint_data, length);</div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;        <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0; i &lt; length; ++i)</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;            data[i] = uint_data[i] &amp; 1;</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;    }</div><div class="line"><a name="l00063"></a><span class="lineno"><a class="line" href="class_p_r_g.html#a83bcd8ff830fa32a3ceb389f5d1a4985">   63</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_p_r_g.html#a83bcd8ff830fa32a3ceb389f5d1a4985">random_data_unaligned</a>(<span class="keywordtype">void</span> *data, <span class="keywordtype">int</span> nbytes) {</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;        <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> tmp[<a class="code" href="config_8h.html#a737cfc77a544a045fab8d3c24f70de11">AES_BATCH_SIZE</a>];</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;        <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0; i &lt; nbytes/(<a class="code" href="config_8h.html#a737cfc77a544a045fab8d3c24f70de11">AES_BATCH_SIZE</a>*16); i++) {</div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;            <a class="code" href="class_p_r_g.html#a822a2e39f1d2629b881ce9b3b8d66bf9">random_block</a>(tmp, <a class="code" href="config_8h.html#a737cfc77a544a045fab8d3c24f70de11">AES_BATCH_SIZE</a>);</div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;            memcpy((16*i*<a class="code" href="config_8h.html#a737cfc77a544a045fab8d3c24f70de11">AES_BATCH_SIZE</a>)+(uint8_t*)data, tmp, 16*AES_BATCH_SIZE);</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;        }</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;        <span class="keywordflow">if</span> (nbytes % (16*<a class="code" href="config_8h.html#a737cfc77a544a045fab8d3c24f70de11">AES_BATCH_SIZE</a>) != 0) {</div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;            <a class="code" href="class_p_r_g.html#a822a2e39f1d2629b881ce9b3b8d66bf9">random_block</a>(tmp, <a class="code" href="config_8h.html#a737cfc77a544a045fab8d3c24f70de11">AES_BATCH_SIZE</a>);</div><div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;            memcpy((nbytes/(16*<a class="code" href="config_8h.html#a737cfc77a544a045fab8d3c24f70de11">AES_BATCH_SIZE</a>)*(16*<a class="code" href="config_8h.html#a737cfc77a544a045fab8d3c24f70de11">AES_BATCH_SIZE</a>))+(uint8_t*) data, tmp, nbytes%(16*<a class="code" href="config_8h.html#a737cfc77a544a045fab8d3c24f70de11">AES_BATCH_SIZE</a>));</div><div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;        }</div><div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;    }</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;</div><div class="line"><a name="l00075"></a><span class="lineno"><a class="line" href="class_p_r_g.html#a822a2e39f1d2629b881ce9b3b8d66bf9">   75</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_p_r_g.html#a822a2e39f1d2629b881ce9b3b8d66bf9">random_block</a>(<a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> * data, <span class="keywordtype">int</span> nblocks=1) {</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;        <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; nblocks; ++i) {</div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;            data[i] = <a class="code" href="utils_2block_8h.html#a371865208357f993ac4e691d54bd806d">makeBlock</a>(0LL, counter++);</div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;        }</div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;        <span class="keywordtype">int</span> i = 0;</div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;        <span class="keywordflow">for</span>(; i &lt; nblocks-<a class="code" href="config_8h.html#a737cfc77a544a045fab8d3c24f70de11">AES_BATCH_SIZE</a>; i+=<a class="code" href="config_8h.html#a737cfc77a544a045fab8d3c24f70de11">AES_BATCH_SIZE</a>) {</div><div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;            AES_ecb_encrypt_blks(data+i, AES_BATCH_SIZE, &amp;aes);</div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;        }</div><div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;        AES_ecb_encrypt_blks(data+i, (AES_BATCH_SIZE &gt;  nblocks-i) ? nblocks-i:AES_BATCH_SIZE, &amp;aes);</div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;    }</div><div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;</div><div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;    <span class="keyword">template</span>&lt;<span class="keyword">typename</span> T, <span class="keyword">typename</span> ... L&gt;</div><div class="line"><a name="l00087"></a><span class="lineno"><a class="line" href="class_p_r_g.html#ab8560a2768e2ed1d9ce3cdc26a3b793d">   87</a></span>&#160;        <span class="keywordtype">void</span> <a class="code" href="class_p_r_g.html#ab8560a2768e2ed1d9ce3cdc26a3b793d">random_bn</a>(T t, L... l) {</div><div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;            <a class="code" href="class_p_r_g.html#ab8560a2768e2ed1d9ce3cdc26a3b793d">random_bn</a>(l...);</div><div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;            <a class="code" href="class_p_r_g.html#ab8560a2768e2ed1d9ce3cdc26a3b793d">random_bn</a>(t);</div><div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;        }</div><div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;</div><div class="line"><a name="l00092"></a><span class="lineno"><a class="line" href="class_p_r_g.html#a71453a36645027b3da285277b73e5a14">   92</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_p_r_g.html#a71453a36645027b3da285277b73e5a14">random_bn</a>(bn_t a, <span class="keywordtype">int</span> sign = BN_POS, <span class="keywordtype">int</span> bits = <a class="code" href="utils__ec_8h.html#a1c3815a8647e6c0fd8e19b2107f2e4fd">BIT_LEN</a>) {</div><div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;        <span class="keywordtype">int</span> digits;</div><div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;        SPLIT(bits, digits, bits, BN_DIG_LOG);</div><div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;        digits += (bits &gt; 0 ? 1 : 0);</div><div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;        bn_grow(a, digits);</div><div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;        <a class="code" href="class_p_r_g.html#a3b64a0c91c31cec853c1829953409520">random_data</a>((uint8_t*)a-&gt;dp, digits * <span class="keyword">sizeof</span>(dig_t));</div><div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;        a-&gt;used = digits;</div><div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;        a-&gt;sign = sign;</div><div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;        <span class="keywordflow">if</span> (bits &gt; 0) {</div><div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;            dig_t mask = ((dig_t)1 &lt;&lt; (dig_t)bits) - 1;</div><div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;            a-&gt;dp[a-&gt;used - 1] &amp;= mask;</div><div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;        }</div><div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;        bn_trim(a);</div><div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;    }</div><div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;</div><div class="line"><a name="l00107"></a><span class="lineno"><a class="line" href="class_p_r_g.html#a925ec137b5d9e2ba1ac05a4789567a5e">  107</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_p_r_g.html#a925ec137b5d9e2ba1ac05a4789567a5e">random_bn</a>(bn_t *a, <span class="keywordtype">int</span> length=1, <span class="keywordtype">int</span> sign = BN_POS, <span class="keywordtype">int</span> bits = <a class="code" href="utils__ec_8h.html#a1c3815a8647e6c0fd8e19b2107f2e4fd">BIT_LEN</a>) {</div><div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;        <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0; i &lt; length; ++i)</div><div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;            <a class="code" href="class_p_r_g.html#ab8560a2768e2ed1d9ce3cdc26a3b793d">random_bn</a>(a[i]);</div><div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;    }</div><div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;</div><div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;    <span class="keyword">template</span>&lt;<span class="keyword">typename</span> T, <span class="keyword">typename</span> ... L&gt;</div><div class="line"><a name="l00113"></a><span class="lineno"><a class="line" href="class_p_r_g.html#a0413492d30592c36c835091915bc9104">  113</a></span>&#160;        <span class="keywordtype">void</span> <a class="code" href="class_p_r_g.html#a0413492d30592c36c835091915bc9104">random_eb</a>(T t, L... l) {</div><div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;            <a class="code" href="class_p_r_g.html#a0413492d30592c36c835091915bc9104">random_eb</a>(l...);</div><div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;            <a class="code" href="class_p_r_g.html#a0413492d30592c36c835091915bc9104">random_eb</a>(t);</div><div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;        }</div><div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;</div><div class="line"><a name="l00118"></a><span class="lineno"><a class="line" href="class_p_r_g.html#aa84e72965df430ab422ea6fa41ac4265">  118</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_p_r_g.html#aa84e72965df430ab422ea6fa41ac4265">random_eb</a>(eb_t p) {</div><div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;        bn_t n, k;</div><div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;        bn_new(k);</div><div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;        bn_new(n);</div><div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;        eb_curve_get_ord(n);</div><div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;        <a class="code" href="class_p_r_g.html#ab8560a2768e2ed1d9ce3cdc26a3b793d">random_bn</a>(k, BN_POS, bn_bits(n));</div><div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;        bn_mod(k, k, n);</div><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;        eb_mul_gen(p, k);</div><div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;    }</div><div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;</div><div class="line"><a name="l00128"></a><span class="lineno"><a class="line" href="class_p_r_g.html#ac79707eb0fae38722f8e5ea37b7ba7f3">  128</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_p_r_g.html#ac79707eb0fae38722f8e5ea37b7ba7f3">random_eb</a>(eb_t *p, <span class="keywordtype">int</span> length=1) {</div><div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;        bn_t n, k;</div><div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;        bn_new(k);</div><div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;        bn_new(n);</div><div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;        eb_curve_get_ord(n);</div><div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;        <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0; i &lt; length; ++i) {</div><div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;            <a class="code" href="class_p_r_g.html#ab8560a2768e2ed1d9ce3cdc26a3b793d">random_bn</a>(k, BN_POS, bn_bits(n));</div><div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;            bn_mod(k, k, n);</div><div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;            eb_mul_gen(p[i], k);</div><div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;        }</div><div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;    }</div><div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;</div><div class="line"><a name="l00140"></a><span class="lineno"><a class="line" href="class_p_r_g.html#aca0e5e9c263b4062c25bd2f0530eaebb">  140</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_p_r_g.html#aca0e5e9c263b4062c25bd2f0530eaebb">random_mpz</a>(mpz_t out, <span class="keywordtype">int</span> nbits) {</div><div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;        <span class="keywordtype">int</span> nbytes = (nbits+1)/8;</div><div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;        uint8_t * data = <span class="keyword">new</span> uint8_t[nbytes+16];</div><div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;        <a class="code" href="class_p_r_g.html#a3b64a0c91c31cec853c1829953409520">random_data</a>(data, nbytes+16);</div><div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;        <span class="keywordtype">int</span> n = nbytes;</div><div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;        <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 3; i &gt;= 0; i--) {</div><div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;            data[i] = (<span class="keywordtype">unsigned</span> char) (n % (1 &lt;&lt; 8));</div><div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;            n /= (1 &lt;&lt; 8);</div><div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;        }</div><div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;        FILE *fp = fmemopen(data, nbytes+16, <span class="stringliteral">&quot;rb&quot;</span>);</div><div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;        <span class="keywordtype">int</span> res = mpz_inp_raw(out, fp);</div><div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;        assert(res != 0);</div><div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;    }</div><div class="line"><a name="l00153"></a><span class="lineno"><a class="line" href="class_p_r_g.html#ad58d1a383da97703f0af25d4eb0179d9">  153</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_p_r_g.html#ad58d1a383da97703f0af25d4eb0179d9">random_mpz</a>(mpz_t rop, <span class="keyword">const</span> mpz_t n) {</div><div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;        <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> size = mpz_sizeinbase(n, 2);</div><div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;        <span class="keywordflow">while</span>(1) {</div><div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;            <a class="code" href="class_p_r_g.html#aca0e5e9c263b4062c25bd2f0530eaebb">random_mpz</a>(rop, size);</div><div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;            <span class="keywordflow">if</span>(mpz_cmp(rop, n) &lt; 0) {</div><div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;                <span class="keywordflow">break</span>;</div><div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;            }</div><div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;        }</div><div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;    }</div><div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;};</div><div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;<span class="preprocessor">#endif// PRP_H__</span></div><div class="ttc" id="class_p_r_g_html_ac79707eb0fae38722f8e5ea37b7ba7f3"><div class="ttname"><a href="class_p_r_g.html#ac79707eb0fae38722f8e5ea37b7ba7f3">PRG::random_eb</a></div><div class="ttdeci">void random_eb(eb_t *p, int length=1)</div><div class="ttdef"><b>Definition:</b> prg.h:128</div></div>
<div class="ttc" id="config_8h_html_a737cfc77a544a045fab8d3c24f70de11"><div class="ttname"><a href="config_8h.html#a737cfc77a544a045fab8d3c24f70de11">AES_BATCH_SIZE</a></div><div class="ttdeci">#define AES_BATCH_SIZE</div><div class="ttdef"><b>Definition:</b> config.h:4</div></div>
<div class="ttc" id="class_p_r_g_html_a364a86de7a055f92198d2d8762f0288c"><div class="ttname"><a href="class_p_r_g.html#a364a86de7a055f92198d2d8762f0288c">PRG::random_bool</a></div><div class="ttdeci">void random_bool(bool *data, int length)</div><div class="ttdef"><b>Definition:</b> prg.h:57</div></div>
<div class="ttc" id="class_p_r_g_html_a6581a2e36b6441e589e19e1af0ecba79"><div class="ttname"><a href="class_p_r_g.html#a6581a2e36b6441e589e19e1af0ecba79">PRG::PRG</a></div><div class="ttdeci">PRG(const void *seed=nullptr, int id=0)</div><div class="ttdef"><b>Definition:</b> prg.h:19</div></div>
<div class="ttc" id="class_p_r_g_html_a567930c31c3371f18099e5c8302aff71"><div class="ttname"><a href="class_p_r_g.html#a567930c31c3371f18099e5c8302aff71">PRG::aes</a></div><div class="ttdeci">AES_KEY aes</div><div class="ttdef"><b>Definition:</b> prg.h:18</div></div>
<div class="ttc" id="garble_2block_8h_html_a65abbf31b0a30290189cdb5059b5f785"><div class="ttname"><a href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a></div><div class="ttdeci">__m128i block</div><div class="ttdef"><b>Definition:</b> block.h:8</div></div>
<div class="ttc" id="config_8h_html"><div class="ttname"><a href="config_8h.html">config.h</a></div></div>
<div class="ttc" id="utils_2block_8h_html_a939b7dd0e7479964d6fe6984b90dd5ce"><div class="ttname"><a href="utils_2block_8h.html#a939b7dd0e7479964d6fe6984b90dd5ce">xorBlocks</a></div><div class="ttdeci">block xorBlocks(block x, block y)</div><div class="ttdef"><b>Definition:</b> block.h:35</div></div>
<div class="ttc" id="utils_2block_8h_html_a371865208357f993ac4e691d54bd806d"><div class="ttname"><a href="utils_2block_8h.html#a371865208357f993ac4e691d54bd806d">makeBlock</a></div><div class="ttdeci">#define makeBlock(X, Y)</div><div class="ttdef"><b>Definition:</b> block.h:69</div></div>
<div class="ttc" id="class_p_r_g_html_aa84e72965df430ab422ea6fa41ac4265"><div class="ttname"><a href="class_p_r_g.html#aa84e72965df430ab422ea6fa41ac4265">PRG::random_eb</a></div><div class="ttdeci">void random_eb(eb_t p)</div><div class="ttdef"><b>Definition:</b> prg.h:118</div></div>
<div class="ttc" id="utils__ec_8h_html_a1c3815a8647e6c0fd8e19b2107f2e4fd"><div class="ttname"><a href="utils__ec_8h.html#a1c3815a8647e6c0fd8e19b2107f2e4fd">BIT_LEN</a></div><div class="ttdeci">#define BIT_LEN</div><div class="ttdef"><b>Definition:</b> utils_ec.h:10</div></div>
<div class="ttc" id="struct_a_e_s___k_e_y_html"><div class="ttname"><a href="struct_a_e_s___k_e_y.html">AES_KEY</a></div><div class="ttdef"><b>Definition:</b> aes.h:57</div></div>
<div class="ttc" id="class_p_r_g_html_a822a2e39f1d2629b881ce9b3b8d66bf9"><div class="ttname"><a href="class_p_r_g.html#a822a2e39f1d2629b881ce9b3b8d66bf9">PRG::random_block</a></div><div class="ttdeci">void random_block(block *data, int nblocks=1)</div><div class="ttdef"><b>Definition:</b> prg.h:75</div></div>
<div class="ttc" id="class_p_r_g_html_aca0e5e9c263b4062c25bd2f0530eaebb"><div class="ttname"><a href="class_p_r_g.html#aca0e5e9c263b4062c25bd2f0530eaebb">PRG::random_mpz</a></div><div class="ttdeci">void random_mpz(mpz_t out, int nbits)</div><div class="ttdef"><b>Definition:</b> prg.h:140</div></div>
<div class="ttc" id="class_p_r_g_html_a71e9b3256b36b72e1198064469381b2c"><div class="ttname"><a href="class_p_r_g.html#a71e9b3256b36b72e1198064469381b2c">PRG::reseed</a></div><div class="ttdeci">void reseed(const void *key, uint64_t id=0)</div><div class="ttdef"><b>Definition:</b> prg.h:41</div></div>
<div class="ttc" id="class_p_r_g_html_ad58d1a383da97703f0af25d4eb0179d9"><div class="ttname"><a href="class_p_r_g.html#ad58d1a383da97703f0af25d4eb0179d9">PRG::random_mpz</a></div><div class="ttdeci">void random_mpz(mpz_t rop, const mpz_t n)</div><div class="ttdef"><b>Definition:</b> prg.h:153</div></div>
<div class="ttc" id="utils__ec_8h_html"><div class="ttname"><a href="utils__ec_8h.html">utils_ec.h</a></div></div>
<div class="ttc" id="aes_8h_html"><div class="ttname"><a href="aes_8h.html">aes.h</a></div></div>
<div class="ttc" id="class_p_r_g_html_a925ec137b5d9e2ba1ac05a4789567a5e"><div class="ttname"><a href="class_p_r_g.html#a925ec137b5d9e2ba1ac05a4789567a5e">PRG::random_bn</a></div><div class="ttdeci">void random_bn(bn_t *a, int length=1, int sign=BN_POS, int bits=BIT_LEN)</div><div class="ttdef"><b>Definition:</b> prg.h:107</div></div>
<div class="ttc" id="class_p_r_g_html"><div class="ttname"><a href="class_p_r_g.html">PRG</a></div><div class="ttdef"><b>Definition:</b> prg.h:16</div></div>
<div class="ttc" id="class_p_r_g_html_abbf584745c33fc90ba28cc4af194ce1a"><div class="ttname"><a href="class_p_r_g.html#abbf584745c33fc90ba28cc4af194ce1a">PRG::counter</a></div><div class="ttdeci">uint64_t counter</div><div class="ttdef"><b>Definition:</b> prg.h:17</div></div>
<div class="ttc" id="class_p_r_g_html_ab8560a2768e2ed1d9ce3cdc26a3b793d"><div class="ttname"><a href="class_p_r_g.html#ab8560a2768e2ed1d9ce3cdc26a3b793d">PRG::random_bn</a></div><div class="ttdeci">void random_bn(T t, L... l)</div><div class="ttdef"><b>Definition:</b> prg.h:87</div></div>
<div class="ttc" id="class_p_r_g_html_a71453a36645027b3da285277b73e5a14"><div class="ttname"><a href="class_p_r_g.html#a71453a36645027b3da285277b73e5a14">PRG::random_bn</a></div><div class="ttdeci">void random_bn(bn_t a, int sign=BN_POS, int bits=BIT_LEN)</div><div class="ttdef"><b>Definition:</b> prg.h:92</div></div>
<div class="ttc" id="class_p_r_g_html_a3b64a0c91c31cec853c1829953409520"><div class="ttname"><a href="class_p_r_g.html#a3b64a0c91c31cec853c1829953409520">PRG::random_data</a></div><div class="ttdeci">void random_data(void *data, int nbytes)</div><div class="ttdef"><b>Definition:</b> prg.h:49</div></div>
<div class="ttc" id="class_p_r_g_html_a0413492d30592c36c835091915bc9104"><div class="ttname"><a href="class_p_r_g.html#a0413492d30592c36c835091915bc9104">PRG::random_eb</a></div><div class="ttdeci">void random_eb(T t, L... l)</div><div class="ttdef"><b>Definition:</b> prg.h:113</div></div>
<div class="ttc" id="class_p_r_g_html_a83bcd8ff830fa32a3ceb389f5d1a4985"><div class="ttname"><a href="class_p_r_g.html#a83bcd8ff830fa32a3ceb389f5d1a4985">PRG::random_data_unaligned</a></div><div class="ttdeci">void random_data_unaligned(void *data, int nbytes)</div><div class="ttdef"><b>Definition:</b> prg.h:63</div></div>
<div class="ttc" id="utils_2block_8h_html"><div class="ttname"><a href="utils_2block_8h.html">block.h</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_eec959d81771dc8b1a750b834e1341eb.html">emp-tool</a></li><li class="navelem"><a class="el" href="dir_363cbed62d1567d90b8cbb6bda69428f.html">utils</a></li><li class="navelem"><a class="el" href="prg_8h.html">prg.h</a></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.12 </li>
  </ul>
</div>
</body>
</html>
